
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
<#include "../common/header.ftl">
    <script src="/js/plugins/jquery-validation/jquery.validate.min.js"></script>
   <#-- <script src="/js/plugins/jquery-validation/messages_cn.js"></script>-->
</head>

<script>
        function moveAll(srcEl,targetEl) {
            //console.log($(".allRoles option"));
            $("."+srcEl+" option").appendTo($("."+targetEl))
        }

        function moveSelected(srcEl,targetEl) {
            //console.log($(".allRoles option"));
            $("."+srcEl+" option:selected").appendTo($("."+targetEl))
        }
    $(function () {


        if($("#admin").prop("checked")){
            allRole=$("#role").detach()
        }

        var allRole;
        $("#admin").click(function () {
            if(this.checked){

            allRole=$("#role").detach()
            }else {
                $(this).closest("div").after(allRole)
            }
        })

        var selRoles = $(".selfRoles option")

        var allRoles = $(".allRoles option")

        var ids = $.map(selRoles,function (option) {
            return option.value;
        })

        $.each(allRoles,function (index,option) {
            if($.inArray(option.value,ids)>=0){
                option.remove()
            }
        })
        $("#btn_submit").click(function () {
            $(".selfRoles option").prop("selected",true)
            $.messager.confirm("温馨提示","确定保存吗?",function () {
               $("#editForm").submit();
            })

        })

    })

</script>
<body>

<div class="container " style="margin-top: 20px">
<#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
        <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">员工编辑</h1>
                </div>
            </div>
            <div class="row col-sm-10">
                <form class="form-horizontal" action="/employee/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" value="${(entity.id)!}" name="id" id="empid">
                    <div class="form-group" >
                        <label for="name" class="col-sm-2 control-label">用户名：</label>
                        <div class="col-sm-6">
                        <input type="text" class="form-control" id="name" name="name" value="${(entity.name)!}" placeholder="请输入用户名">
                        </div>
                    </div>
                       <#if !entity??>
                        <div class="form-group">
                            <label for="password" class="col-sm-2 control-label">密码：</label>
                            <div class="col-sm-6">
                            <input type="password" class="form-control" id="password"  name="password"  placeholder="请输入密码">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="repassword" class="col-sm-2 control-label">验证密码：</label>
                            <div class="col-sm-6">
                            <input type="password" class="form-control" name="repassword" id="repassword" placeholder="再输入一遍密码">
                            </div>
                        </div>
                       </#if>
                    <div class="form-group">
                        <label for="email" class="col-sm-2 control-label">Email：</label>
                        <div class="col-sm-6">
                        <input type="text" class="form-control" id="email" name="email" value="${(entity.email)!}" placeholder="请输入邮箱">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="age" class="col-sm-2 control-label">年龄：</label>
                        <div class="col-sm-6">
                        <input type="text" class="form-control" id="age" name="age" value="${(entity.age)!}" placeholder="请输入年龄">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="dept" class="col-sm-2 control-label">部门：</label>
                        <div class="col-sm-6">
                        <select class="form-control" id="dept" name="dept.id">
                                 <#list depts as d >
                                    <option value="${(d.id)!}" >${(d.name)!}</option>
                                 </#list>
                        </select>
                        </div>
                        
                    </div>
                    <script>
                        <#if (entity.dept.id)?? >
                            $("#dept option[value=${(entity.dept.id)!}]").prop("selected",true)
                        </#if>
                    </script>

                    <div class="form-group">
                        <label for="admin" class="col-sm-2 control-label">超级管理员：</label>
                        <label class="checkbox-inline" style="margin-left: 15px;">
                            <input type="checkbox" id="admin" name="admin" <#if (entity.admin)?? && entity.admin>
                                   selected
                            </#if>>
                        </label>
                    </div>

                    <div class="form-group" id="role">
                        <div>
                            <label for="role" class="control-label" style="margin-left: 60px">角色：</label>
                        </div>
                        <div class="row" style="margin-top: 10px">
                            <div class="col-sm-4 col-sm-offset-1">
                                <select multiple class="form-control allRoles" size="15">
                                        <#list roles as r>
                                            <option value="${r.id}" >${r.name}</option>
                                        </#list>
                                </select>
                            </div>

                            <div class="col-sm-2" style="margin-top: 60px;" align="center">
                                <div >
                                    <a type="button" class="btn btn-info  "  style="margin-top: 10px"
                                       onclick="moveSelected('allRoles', 'selfRoles')">&nbsp;&gt;&nbsp;</a>
                                    <br>
                                    <a type="button" class="btn btn-info " style="margin-top: 10px"
                                       onclick="moveSelected('selfRoles', 'allRoles')">&nbsp;&lt;&nbsp;</a>
                                    <br>
                                    <a type="button" class="btn btn-info " style="margin-top: 10px"
                                       onclick="moveAll('allRoles', 'selfRoles')">&gt;&gt;</a>
                                    <br>
                                    <a type="button" class="btn btn-info " style="margin-top: 10px"
                                       onclick="moveAll('selfRoles', 'allRoles')">&lt;&lt;</a>
                                </div>
                            </div>

                            <div class="col-sm-4">
                                <select multiple class="form-control selfRoles" size="15" name="ids">
                                        <#list (entity.roleList)! as r >
                                            <option value="${r.id}" >${r.name}</option>
                                        </#list>
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-offset-1 col-sm-6">
                            <button type="button" id="btn_submit" class="btn btn-default">保存</button>
                            <button type="reset" class="btn btn-default">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
</body>
</html>